<cfcomponent output="false">
	<cfset $ = application.helpers />
	<cfset $view = application.v />
	<cfset $service = application.s />
	
	<!--- --->
	
	<cffunction name="renderFunds" access="public" output="true" returntype="string">
		<cfargument name="isQuery" required="false" default="true" />
		
		<cfset var local = {} />
		
		<cfif structKeyExists(cookie,'tag')>
			<cfset arguments.tags = replace(cookie.tag,'|',',','ALL') />
		</cfif>
		
		<cfset local.funds = application.s.fundService.getFunds(argumentCollection=arguments) />
		
		<cfsavecontent variable="local.result">
			
			<cfset local.searchArgs = [] /> <!--- store active args here. --->
			<cfset local.searchArgFunction = [] /> <!--- store active args here. --->
			
			<!--- analyze the arguments --->
			<cfif structKEyExists(arguments,'zip') and arguments.zip neq ''>
				<cfset arrayAppend(local.searchArgs,'Zip Code') />
				<cfset arrayAppend(local.searchArgFunction,'SearchSummary.clearZip(this);') />
			</cfif>
			
			<cfif structKEyExists(arguments,'title_description') and arguments.title_description neq ''>
				<cfset arrayAppend(local.searchArgs,'Title or Description') />
				<cfset arrayAppend(local.searchArgFunction,'SearchSummary.clearTitleDescription(this);') />
			</cfif>
			
			<cfif structKEyExists(arguments,'state_id') and arguments.state_id neq ''>
				<cfset arrayAppend(local.searchArgs,'State') />
				<cfset arrayAppend(local.searchArgFunction,'SearchSummary.clearState(this);') />
			</cfif>
			
			<cfif structKEyExists(arguments,'city') and arguments.city neq ''>
				<cfset arrayAppend(local.searchArgs,'City') />
				<cfset arrayAppend(local.searchArgFunction,'SearchSummary.clearCity(this);') />
			</cfif>
			
			<cfif structKEyExists(arguments,'fundID') and arguments.fundID neq ''>
				<cfset arrayAppend(local.searchArgs,'Fund ID') />
				<cfset arrayAppend(local.searchArgFunction,'SearchSummary.clearFundID(this);') />
			</cfif>
			
			<cfif structKEyExists(arguments,'start_date') and arguments.start_date neq ''>
				<cfset arrayAppend(local.searchArgs,'Created Date') />
				<cfset arrayAppend(local.searchArgFunction,'SearchSummary.clearStartDate(this);') />
			</cfif>
			
			<cfif structKEyExists(arguments,'owner_name') and arguments.owner_name neq ''>
				<cfset arrayAppend(local.searchArgs,'Owner Name') />
				<cfset arrayAppend(local.searchArgFunction,'SearchSummary.clearOwnerName(this);') />
			</cfif>
			
			<cfif structKEyExists(arguments,'tags') and arguments.tags neq ''>
				<cfset arrayAppend(local.searchArgs,'Tags') />
				<cfset arrayAppend(local.searchArgFunction,'SearchSummary.clearTags(this);') />
			</cfif>
			
			<cfif arguments.isQuery and arrayLen(local.searchArgs) gt 0>
				<div class="search-summary instructions">
					<b>#local.funds.recordcount#</b> fund<cfif local.funds.recordcount gt 1>s</cfif> matching search.
					
					<span class="search-summary-items" style="margin-top:-3px;margin-left:5px;"><button onclick="SearchSummary.clearAll();" style="background-color:##c5c5c5;" class="small">clear</button></span>
					
					<cfloop array="#local.searchArgs#" index="local.i" item="local.item">
						<span class="search-summary-items"><a onclick="#local.searchArgFunction[local.i]#">#local.item#</a><cfif local.i gt 1>,&nbsp;&nbsp;</cfif></span>
					</cfloop>
					
					<span class="search-summary-items">Searching By:&nbsp;&nbsp;</span>
				</div>
			</cfif>
			
			<cfloop query="local.funds">
				#renderFund(
					id=local.funds.id,
					title=local.funds.title,
					target=local.funds.amount,
					description=local.funds.description,
					who=local.funds.who,
					payment_total=local.funds.payment_total,
					has_thumbnail=local.funds.has_thumbnail,
					city=local.funds.city,  
					state=local.funds.state,
					first_name=local.funds.first_name,
					last_name=local.funds.last_name,
					created=local.funds.created,
					tags=local.funds.tags,
					fundID=local.funds.fund_id,
					userID=local.funds.user_id,
					my_plan_count=local.funds.my_plan_count,
					isQuery=arguments.isQuery
				)#
			</cfloop>
			<cfif arguments.isQuery>
				<div style="height:150px;">
					&nbsp;
				</div>
			</cfif>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderFund" access="public" output="true" returntype="string">
		<cfargument name="title" required="true" />
		<cfargument name="description" required="false" default="" />
		
		<cfset var local = {} />
		
		<cfif arguments.my_plan_count gt 0 and session.loggedin>
			<cfset local.my_plans = $service.paymentService.getPaymentPlans(arguments.id,session.user.id) />
		</cfif>
		
		<cfsavecontent variable="local.result">
			<div class="fund" id="fund_#arguments.fundID#">
				#_renderFundTabs(argumentCollection=arguments)#
				
				<div class="fund-progress">
					#_renderFundProgress(argumentCollection=arguments)#
				</div>
				<div class="fund-top">
					<div class="fund-top-title">
						#_renderFundTitle(argumentCollection=arguments)#
					</div>
					<div class="fund-top-tags">
						<cfloop list="#arguments.tags#" index="local.i">
							#_renderFundTag(local.i)#
						</cfloop>
						#_renderFundID(arguments.fundID)#
					</div>
				</div>
				<table class="fund-contents" cellspacing="0" cellpadding="0" valign="top">
					<tr class="overview current">
						<td class="fund-contents-photo">
							#_renderFundPhoto(argumentCollection=arguments)#
						</td>
						<td class="fund-contents-main">
							<div class="fund-main-top-description">
								#_renderFundDescription(argumentCollection=arguments)#
							</div>
							<div class="fund-paymentArea" style="display:none;">
							</div>
							<div class="fund-contents-loading" style="display:none;">
								#$.render.img(path='loading2.gif',style="margin:74px 0px 0px 260px;")#
							</div>
						</td>
						<td class="fund-contents-meta">
							#_renderMeta(argumentCollection=arguments)#
						</td>
					</tr>
					<tr class="share" style="display:none;">
						<td></td>
					</tr>
					<tr class="payments" style="display:none;">
						<td colspan="99" style="">
							Payments
						</td>
					</tr>
					<tr class="reports" style="display:none;">
						<td colspan="99">
							Reports
						</td>
					</tr>
					<tr class="transaction" style="display:none;">
						<td colspan="99">
							Transaction
						</td>
					</tr>
				</table>
				<div class="fund-bottom">
					#_renderIcons(argumentCollection=arguments)#
				</div>
				<div class="fund-paymentPlans">
					<cfif arguments.my_plan_count gt 0 and session.loggedin and session.user.id neq arguments.userID>
						#$view.paymentView.renderPaymentPlans(local.my_plans,arguments.target)#
					</cfif>
				</div>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderFundTitle" access="private" output="true" returntype="string">
		<cfargument name="title" required="true" />
		<cfargument name="userID" required="true" />
		<cfargument name="ID" required="true" />
		<cfargument name="who" required="true" />
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<cfif len(session.user.id) eq 32>
				<cfif session.user.id eq arguments.userID>
					#$.render.img(path='/icons/star_green.png',class='fund-favorite',bubble="This is Your Fund.")#
				<cfelse>
					<span id="notfavorite_#arguments.id#" <cfif session.user.favorites contains '#arguments.id#'>style="display:none;"</cfif>>
						#$.render.img(path='/icons/star.png',class='fund-favorite not_favorite_this',id="notfav_#arguments.id#")#
						#$.render.img(
							path='/icons/star_gold_hover.png',
							class='fund-favorite hidden favorite_this',
							id="fav_#arguments.id#",
							bubble="Click to add as a Favorite Fund.",
							onclick="Fund.addFavorite('#arguments.id#');"
						)#
					</span>
					<span id="favorite_#arguments.id#" <cfif not session.user.favorites contains '#arguments.id#'>style="display:none;"</cfif>>
						#$.render.img(
							path='/icons/star_gold.png',
							class='fund-favorite unfavorite_this',
							id="unfav_#arguments.id#",
							bubble="Favorite Fund. (click to un-favorite)",
							onclick="Fund.removeFavorite('#arguments.id#');"
						)#
					</span>
				</cfif>
			<cfelse>
				&nbsp;
			</cfif>
			
			<span class="fund-title">#arguments.title#</span>
	
		 	<div class="fund-who" style="display:none;">
				- #arguments.who# 
				#$.render.img(path='/icons/location.png',style="margin-bottom:-2px;margin-right:-2px;")# 
				#arguments.city#, #arguments.state#
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderFundDescription" access="private" output="true" returntype="string">
		<cfargument name="description" required="true" />
		<cfargument name="who" required="true" />
		<cfargument name="city" required="true" />
		<cfargument name="state" required="true" />
		
		<cfset var local = {} />
		
		<cfif arguments.description contains 'http' or arguments.description contains 'www.'>
			<cfset local.wordArray = listToArray(arguments.description,' ') />
			<cfset local.description = "" />
			<cfloop array="#local.wordArray#" index="local.i">
				<cfif left(local.i,4) eq 'http' or left(local.i,4) eq 'www.'>
					<cfset local.addressArray = listToArray(local.i,'?') />
					<cfset local.i = '<a href="#local.i#" target="_blank">#local.addressArray[1]#</a>'>
				</cfif>
				<cfset local.description = local.description & ' ' & local.i />
			</cfloop>
			<cfset arguments.description = local.description />
		</cfif>
		
		<cfsavecontent variable="local.result">
			<div class="fund-description">
				#left(arguments.description,250)# 
				<cfif len(arguments.description) gt 250>
					&nbsp;&nbsp;&nbsp;<a href="##">more... </a>
				</cfif>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderFundPhoto" access="private" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="photo-buttons">
				<cfif arguments.userID eq session.user.id and arguments.has_thumbnail neq 1>
					<button class="photo-button add" onclick="Upload.openModal('#arguments.fundID#');">#$.render.img(path="icons/upload.png")#</button>
				</cfif>
				<cfif arguments.userID eq session.user.id and arguments.has_thumbnail eq 1>
					<button class="photo-button remove" onclick="Upload.removeThumbnail('#arguments.fundID#');">#$.render.img(path="icons/cancel-circle.png")#</button>
				</cfif>
			</div>
			<cfif arguments.has_thumbnail eq 1>
				#$.render.img(path='#arguments.fundID#/thumb.png?#now()#',class='fund-photo',aws=true,refresh=arguments.isQuery)#
			<cfelse>
				#$.render.img(path='no-image.png',class='fund-photo',aws=true,refresh=arguments.isQuery)#
			</cfif>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderFundProgress" access="private" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<cfset local.class = "fund-progress-bar" />
			<cfset local.percentage = 100 />
			<cfif arguments.target eq '0'>
				<cfset local.class = local.class & "fund-progress-bar-no-target" />
			<cfelse>
				<cfset local.percentage = (arguments.payment_total * 100) / arguments.target />
			</cfif>
			
			<cfif local.percentage gt 100>
				<cfset local.percentage = 100 />
			</cfif>
			
			<div class="fund-progress-bar <cfif arguments.target eq '0'>fund-progress-bar-no-target</cfif>" style="width:#local.percentage#%"></div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderFundTag" access="public" output="true" returntype="string">
		<cfargument name="tag" required="true" />
		<cfargument name="isAdd" required="false" default="false" />
		<cfargument name="popular" required="false" default="false" />
		<cfargument name="hide" required="false" default="false" />
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="fund-tag<cfif arguments.isAdd> inactive</cfif><cfif arguments.popular> popular</cfif>" title="#arguments.tag#" onclick="Tag.clicked(this);" value="#arguments.tag#" style="<cfif arguments.hide>display:none;</cfif>">
				<span class="tag-contents">				
					<span style="color:grey">##</span>#arguments.tag#
				</span>
				<span class="tag-add" style="display:none;">				
					<a onclick="javascript:Tag.add(this);">Add?</a>
				</span>
				<span class="tag-remove" style="display:none;">				
					<a onclick="javascript:Tag.remove(this);">Remove?</a>
				</span>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderFundTarget" access="private" output="true" returntype="string">
		<cfargument name="tag" required="true" />
		<cfargument name="icon" required="false" default="true" />
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="fund-tag target" title="Fund Target Amount">
				#arguments.tag#
				<cfif arguments.icon>
					#$.render.img(path='/icons/target.png',style="margin:-1px -4px -3px 1px;height:15px;")#
				</cfif>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderFundID" access="private" output="true" returntype="string">
		<cfargument name="tag" required="true" />
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="fund-tag fundID" title="Fund ID">
				#arguments.tag#
				#$.render.img(path='/icons/fundrID.png',style="margin:-2px -4px -3px -1px;height:16px;")#
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderOwner" access="private" output="true" returntype="string">
		<cfargument name="tag" required="true" />
		
		<cfset var local = {} />
		
		<cfset local.test = true />
		
		<cfif randrange(1,100) mod 2 eq 1>
			<cfset local.test = false />
		</cfif>
		
		<cfsavecontent variable="local.result">
			<div class="fund-tag owner" title="Fund Owner">
				<cfif local.test>
				#$.render.img(path='/icons/yes_facebook.png',style="margin:0px -3px -1px 5px;height:13px;float:right;")#
				<cfelse>
				#$.render.img(path='/icons/no_facebook.png',style="margin:0px -3px -1px 5px;height:13px;float:right;")#
				</cfif>
				#arguments.tag#
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderLocation" access="private" output="true" returntype="string">
		<cfargument name="city" required="true" />
		<cfargument name="state" required="true" />
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="fund-tag location" title="Fund Location">
				#arguments.city#, #arguments.state#			
				#$.render.img(path='/icons/location.png',style="margin:0px -3px -2px 1px;height:13px;")#
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderIcons" access="public" output="true" returntype="string">
		<cfargument name="fundID" required="false" default="" />
				
		<cfset var local = {} />
		
		
		<cfsavecontent variable="local.result">
			<ul class="fund-icons">
				<li style="width:102px;">
					<button style="display:none;background-color:rgb(175, 175, 175);" class="collapse" onclick="javascript:Fund.collapse('#arguments.fundID#');">
						#$.render.img(path='/icons/cancel-circle.png',style="margin-left:-4px;margin-bottom:-2px;height:14px;")# 
						Cancel
					</button>
				</li>
				<li style="width:60px;">
					&nbsp;
				</li>
				<li>
					#$.render.img(path='/icons/donor.png',style="height:25px;")#
					<span class="icon-instructions" style="display:block;">
						5 donors
					</span>				
				</li>
				<li>
					#$.render.img(path='/icons/up.png',style="height:25px;")#
					<span class="icon-instructions" style="display:block;">
						$156 per week
					</span>				
				</li>
				<li>
					#$.render.img(path='/icons/time.png',style="height:25px;")#
					<span class="icon-instructions" style="display:block;">
						24 more weeks
					</span>			
				</li>
				<li>
					#$.render.img(path='/icons/graph.png',style="height:25px;")#
					<span class="icon-instructions" style="display:block;">
						100% funded
					</span>
				</li>
			</ul>
			<cfif arguments.userID eq session.user.id>
				<button class="support" onclick="javascript:Fund.expand('#arguments.fundID#');">
					Edit
				</button>
			<cfelse>
				<button class="support" onclick="javascript:Fund.expand('#arguments.fundID#');">
					#$.render.img(path='/icons/coin_white.png',style="margin-left:-4px;margin-bottom:-2px;")# 
					Support
				</button>
			</cfif>

		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderMeta" access="public" output="true" returntype="string">
		<cfargument name="fundID" required="false" default="" />
		<cfargument name="first_name" required="false" default="" />
		<cfargument name="last_name" required="false" default="" />
		<cfargument name="created" required="false" default="" />
		<cfargument name="who" required="false" default="" />
				
		<cfset var local = {} />
		
		
		<cfsavecontent variable="local.result">
			<ul style="padding-right:5px;">
				<li>#_renderLocation(arguments.city,arguments.state)#</li>
				<li>#_renderOwner(arguments.who)#</li>

				<cfif arguments.target neq '' and arguments.target gt 0>
					<li style="padding-bottom:3px;">
						#_renderFundTarget($.format.money(arguments.target))#
					</li>
				<cfelse>
					<li style="padding-bottom:3px;">
						#_renderFundTarget($.format.money(arguments.payment_total),false)#
					</li>
				</cfif>
			</ul>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderCreateForm" access="public" output="true" returntype="string">
				
		<cfset var local = {} />
		
		<cfset local.formID = "create_fund_form" />
		
		<cfsavecontent variable="local.result">
			#$view.filterView._renderForm(title="Customize your new fund",id=local.formID,collapse=false)#
				
				<div class="instructions">
					<table cellspacing="0" cellpadding="0" style="text-align:center;">
						<tr>
							<td width="33%">Define Target</td>
							<td width="33%">Define End Date</td>
							<td width="34%">Private Fund</td>
						</tr>
						<tr>
							<td>#$.render.radio(name='use_target',value=1,onchange="evaluateNewFundRadios();")#</td>
							<td>#$.render.radio(name='use_end_date',value=0,onchange="evaluateNewFundRadios();")#</td>
							<td>#$.render.radio(name='private',value=0,onchange="evaluateNewFundRadios();")#</td>
						</tr>
					</table>
				</div>
				
				<div class="filter-label instructions" style="margin-top:6px;">
					Fund Title
				</div>
				<input name="title" value="" title="Fund Title" validate="required" style="width:242px;"/>
				<div class="filter-label instructions" bubble="Describe who is in charge of this fund. (will be seen by visitors)" >
					Fund Owner
				</div>
				<input name="who" value="" title="Fund Owner" validate="required" style="width:242px;"/>
				
				<div class="filter-label instructions">
					Description 
				</div>
				<textarea name="description" style="width:242px;" rows="5"></textarea>
				
				
				<div id="target_radio" style="display:inline-block;margin-right:15px;">
					<div class="filter-label instructions">
						Target Amount 
					</div>
					<div style="clear:both;">
						<span class="instructions">$ </span><input title="Target Amount" name="target" validate="money,positive" style="width:55px;margin-bottom:3px;" />
					</div>
				</div>
				
				<div id="end_date_radio" style="display:inline-block;float:right;">
					<div class="filter-label instructions">
						#$.render.star()#End Date 
					</div>
					<div style="clear:both;">
						<input name="end_date" validate="date" style="width:69px;" />
					</div>
				</div>
				
				<div style="clear:both;"></div>
				
				<div class="filterSet-buttons">
					<button class="small" onclick="Fund.create();">Create Fund</button>
				</div>
				
			#$view.filterView.formClose()#
			
			<script type="text/javascript">
				$(document).ready(function(){
					Modal.init('#local.formID#','title',334,255);
					
					jQuery(document).on('keyup','##filterSet_#local.formID# input, ##filterSet_#local.formID# select',function(e){
						if(e.keyCode == 13){
							Fund.create();
						}
					});

					evaluateNewFundRadios = function(){
						var target = +Radio.get("use_target");
						var end_date = +Radio.get("use_end_date");
						var $target = jQuery('##pp_full_res').find('div##target_radio');
						var $end_date = jQuery('##pp_full_res').find('div##end_date_radio');

						$target.show();
						$end_date.hide();
						
						if(end_date + target == 1){
							if(end_date == 1){
								$end_date.css('float','none');
							} else {
								$end_date.css('float','right');
							}
							jQuery('##pp_full_res').find('.filterSet-buttons').css('marginTop','-33px');
						} else {
							jQuery('##pp_full_res').find('.filterSet-buttons').css('marginTop','0px');
						}
						
						$target.hide();
						
						if(target == 1){
							$target.show();
							Validate.addValidation('target','required');
						} else {
							$target.hide();
							Validate.removeValidation('target','required');
						}
						if(end_date == 1){
							$end_date.show();
							Validate.addValidation('end_date','required');
						} else {
							$end_date.hide();
							Validate.removeValidation('end_date','required');
						}
					};

					Modal.callback.#local.formID# = evaluateNewFundRadios;
				});
			</script>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="_renderFundTabs" access="public" output="true" returntype="string">
				
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<cfif len(session.user.id) eq 32 and session.user.id eq arguments.userID>
				<div class="fund-tabs" id="fund_tabs_#arguments.fundID#">
					<ul>
						<li id="#arguments.fundID#_overview" onclick="Tab.change('#arguments.fundID#','overview');" class="fund_tab first selected">overview</li>
						<li id="#arguments.fundID#_share" onclick="Tab.change('#arguments.fundID#','share');" class="fund_tab">Share</li>
						<li id="#arguments.fundID#_payments" onclick="Tab.change('#arguments.fundID#','payments');" class="fund_tab" >Payments</li>
						<li id="#arguments.fundID#_reports" onclick="Tab.change('#arguments.fundID#','reports');" class="fund_tab" >Reports</li>
						<li id="#arguments.fundID#_transaction" onclick="Tab.change('#arguments.fundID#','transaction');"  class="fund_tab last">Transaction Log</li>
					</ul>
				</div>
				<div style="clear:both;"></div>
				<script type="text/javascript">
					Tab['_#arguments.fundID#'] = {};
					Tab['_#arguments.fundID#'].current = 'overview';
					Tab['_#arguments.fundID#'].mailingList = {};
				</script>
			</cfif>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderShare" access="public" output="true" returntype="string">
		<cfargument name="fundID" required="true" />
		
		<cfset sleep(700) />	
		
		<cfset var local = {} />
		
		<cfset local.funds = application.s.fundService.getFunds(argumentCollection=arguments) />
		<cfset local.link = "https://www.fundr.us/#arguments.fundID#" />
		
		<cfsavecontent variable="local.result">
			<td colspan="99">
				#$view.filterView._renderForm(title='Spread the word',collapse="false")#
					<div style="width:616px;margin-bottom:-5px;">
						#$.render.img(
							path="icons/facebook_share.png",
							onclick="Social.facebookShare(
								'#rereplace(local.funds.title,"'","\'",'ALL')#',
								'https://www.fundr.us',
								'#local.funds.description#',
								'#$.site.getVar("homeURL")#?fund=#arguments.fundID#',
								'https://s3.amazonaws.com/FundrImages/#arguments.fundID#/thumb.png'
							)",
							class="social-button"
						)#
						#$.render.img(path="icons/twitter_share.png",class="social-button",style="")#
						<div class="social-link">
							#$.render.img(path="icons/link.png",class="link-icon")# <input spellcheck="false" name="link" onmouseup="$(this).select();" onfocusout="$(this).val('#local.link#');" value="#local.link#">
						</div>
						<iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;width=83&amp;height=21&amp;colorscheme=light&amp;layout=button_count&amp;action=like&amp;show_faces=false&amp;send=false&amp;appId=163131223886885" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:83px; height:23px;" allowTransparency="true"></iframe>
					</div>
				#$view.filterView.formClose()#
				
				<div style="display:inline-block">
					#$view.filterView._renderForm(title='Contacts',collapse="false",leftButton="filter",rightButton="sort",leftAction="Mailing.showFilters('#arguments.fundID#');",rightAction="Mailing.showSort('#arguments.fundID#');")#
						<div class="mailingList" style="width:430px;height:174px;">
							<cfset arguments.contactTags = local.funds.contact_tags />
							#renderMailingList(argumentCollection=arguments)#
						</div>
					#$view.filterView.formClose()#
				</div>
				<div class="composeFilter" style="display:inline-block;margin-left:4px;">
					#$view.filterView._renderForm(title='Compose',collapse="false",rightButton="history",rightAction="Mailing.showHistory('#arguments.fundID#');")#
						<div class="composeDiv" style="width:176px;height:174px;">
							#$view.mailingView.renderInterface(arguments.fundID)#
						</div>
					#$view.filterView.formClose()#
				</div>
				<div class="historyFilter" style="display:none;margin-left:4px;">
					#$view.filterView._renderForm(title='History',collapse="false",rightButton="compose",rightAction="Mailing.showCompose('#arguments.fundID#');")#
						<div style="width:176px;height:174px;">history</div>
					#$view.filterView.formClose()#
				</div>
				<input type="hidden" name="fund_contact_tags_#arguments.fundID#" value="#local.funds.contact_tags#" />
			</td>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderMailingList" access="public" output="true" returntype="string">
		<cfargument name="fundID" required="true" />
		
		<cfset var local = {} />
						
		<cfsavecontent variable="local.result">
			<table class="mailing-list-table" cellspacing="0" cellpadding="0" fundID="#arguments.fundID#">
				<thead>
					#renderFilters(argumentCollection=arguments)#
				</thead>
				<tbody>
					#renderMailingListRows(fundID=arguments.fundID)#
				</tbody>
				<tfoot>
					<tr>
						<td class="check" style="font-size:11px;line-height:20px;color:##7c7c7c;font-weight:normal;">add</td>
						<td class="email"><input validate="email,required,nospace,nocomma" class="mailing-list-input" name="list-email" placeholder="email@domain.com" /></td>
						<td class="name"><input class="mailing-list-input" name="list-name" placeholder="name (optional)" /></td>
						<td class="controls" style="text-align:right;">
							<button class="small selectAll" onclick="Mailing.selectAll('#arguments.fundID#',this);">all</button>
							<button class="small deselect hidden" onclick="Mailing.selectNone('#arguments.fundID#',this);">none</button>
							<button class="disabled small tag" onclick="Mailing.openTagModal('#arguments.fundID#',this);">tag</button>
							<button class="hidden small untag" onclick="Mailing.clearTags('#arguments.fundID#');">untag</button>
							<button class="disabled small delete" onclick="Mailing.deleteEmails(this,'#arguments.fundID#');">delete</button>
						</td>
					</tr>
				</tfoot>
			</table>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderMailingListRow" access="public" output="true" returntype="string">
		<cfargument name="currentRow" required="true" />
		<cfargument name="email" required="true" />
		<cfargument name="fundID" required="true" />
		<cfargument name="name" required="true" />
		<cfargument name="amount" required="true" />
		<cfargument name="tags" required="false" default="" />
		<cfargument name="blankRow" required="false" default="false" />
		<cfargument name="id" required="false" default="" />
		
		<cfset var local = {} />
		
		<cfif arguments.blankRow>
			<cfset arguments.currentRow = 0 />
			<cfset arguments.email = '' />
			<cfset arguments.name = '' />
			<cfset arguments.tags = '' />
			<cfset arguments.amount = '' />
		</cfif>
		
		<cfset arguments.email = $.format.decrypt(arguments.email) />
		
		<cfsavecontent variable="local.result">
			<tr class="<cfif arguments.currentRow mod 2 eq 1>odd </cfif><cfif arguments.blankRow>hidden</cfif>" email="#lcase(arguments.email)#" hastag="#listLen(arguments.tags)#">
				<td class="check">
					<cfset local.style = "display:none;" />
					<cfif arguments.blankRow>
						<cfset local.style = "" />
					</cfif>
					#$.render.img(class="saving",path='loading.gif',style="#local.style#",bubble="Saving...")#
					<input class="<cfif arguments.blankRow>hidden</cfif>" type="checkbox" value="#arguments.id#" onchange="Mailing.checkToggle(this,'#arguments.fundID#');" />
				</td>
				<td class="email">
					<a class="editable" onclick="Mailing.showEdit(this);">#arguments.email#</a>
					<input type="text" class="hidden email-row-input" name="edit-email" value="#arguments.email#" onblur="Mailing.saveEdit(this);" onkeyup="Mailing.saveEdit(this,event.keyCode);" />
				</td>
				<td class="name">
					<a class="editable" onclick="Mailing.showEdit(this);"><cfif arguments.name neq ''>#arguments.name#<cfelse><span class="grey">- no name -</span></cfif></a>
					<input type="text" class="hidden email-row-input" name="edit-name" value="#arguments.name#" onblur="Mailing.saveEdit(this);" onkeyup="Mailing.saveEdit(this,event.keyCode);" />
				</td>
				<td class="tags">
					<cfloop list="#arguments.tags#" index="local.tag">
						<div class="contactTag">#local.tag#</div>
					</cfloop>
				</td>
				<td class="paid">
					<span style="<cfif arguments.amount eq 0>color:##999999;font-weight:normal;</cfif>">#$.format.money(arguments.amount,false)#</span>
				</td>
				<td class="history">1 2 3 4</td>
			</tr>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderMailingListRows" access="public" output="true" returntype="string">
		<cfargument name="fundID" required="true" />

		<cfset var local = {} />
		
		<cfset arguments.includeTags = "" />
		<cfset arguments.excludeTags = "" />
		
		<cfset arguments.includeMailingIDs = "" />
		<cfset arguments.excludeMailingIDs = "" />
		
		<cfset arguments.given = "" />
		
		<cfloop collection="#arguments#" item="local.i">
			<!--- handle tag args --->
			<cfif len(local.i) gt 4 and left(local.i,4) eq 'tag_'>
				<cfif arguments[local.i] neq ''>
					<cfset local.tag = right(local.i,len(local.i)-10) />
					<cfif arguments[local.i] eq 1>
						<cfset arguments.includeTags = listAppend(arguments.includeTags,local.tag) />
					<cfelse>
						<cfset arguments.excludeTags = listAppend(arguments.excludeTags,local.tag) />
					</cfif>
				</cfif>
				<cfset structDelete(arguments,local.i) />
			</cfif>
			
			<!--- handle mailing args --->
			<cfif len(local.i) gt 8 and left(local.i,8) eq 'mailing_'>
				<cfif arguments[local.i] neq ''>
					<cfset local.mailingid = right(local.i,len(local.i)-8) />
					<cfif arguments[local.i] eq 1>
						<cfset arguments.includeMailingIDs = listAppend(arguments.includeMailingIDs,local.mailingid) />
					<cfelse>
						<cfset arguments.excludeMailingIDs = listAppend(arguments.excludeMailingIDs,local.mailingid) />
					</cfif>
				</cfif>
				<cfset structDelete(arguments,local.i) />
			</cfif>
			
			<!--- handle giving toggle --->
			<cfif len(local.i) eq 12 and left(local.i,7) eq 'filter_'>
				<cfif arguments[local.i] eq 1>
					<cfset arguments.given = ' > 0' />
				<cfelseif arguments[local.i] eq 2>
					<cfset arguments.given = ' = 0' />
				</cfif>
				<cfset structDelete(arguments,local.i) />
			</cfif>
		</cfloop>
		
		<cfset local.fund = $service.fundService.getIDByFundID(arguments.fundID) />
		<cfset local.contacts = $service.fundService.getContacts(argumentCollection=arguments,fundID=local.fund.id) />
		
		<cfsavecontent variable="local.result">
			<cfloop query="local.contacts">
				#renderMailingListRow(
					id=local.contacts.id,
					fundID=arguments.fundID,
					currentRow=local.contacts.currentRow,
					email=local.contacts.email,
					name=local.contacts.name,
					amount=local.contacts.amount,
					tags=local.contacts.tags
				)#
			</cfloop>
			<cfif local.contacts.recordcount eq 0>
				<tr class="no_contacts">
					<td colspan="99" style="text-align:center;width:400px;">
						<span class="subInstruction">no contacts</span>
					</td>
				</tr>
			</cfif>
		
		</cfsavecontent>
		
					
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderFilters" access="public" output="true" returntype="string">
		<cfargument name="fundID" required="true" />
		<cfargument name="contactTags" required="false" />

		<cfset var local = {} />
		
		<cfif not structKeyExists(arguments,'contactTags')>
			<cfset local.fund = $service.fundService.getFunds(arguments.fundID) />
			<cfset arguments.contactTags = local.fund.contact_tags />
		</cfif>
		
		<cfset local.fundID = $service.fundService.getIDByFundID(arguments.fundID).id />
		
		<cfset local.mailing = $service.mailingService.getMailings(local.fundID) />
		
		<cfsavecontent variable="local.result">
			<tr class="filters" style="display:none;">
				<td style="width:430px;">
					#$.render.checkboxes(
						name="filter_#arguments.fundID#",
						value="",
						labels=['has given','has not given'],
						values=[1,2],
						onchange="Mailing.toggleGiven('#arguments.fundID#',this);"
					)#
					
					<cfloop list="#arguments.contactTags#" index="local.tag">
						#$.render.triRadio(
							name="tag_#arguments.fundID#_#local.tag#",
							value="",
							label=local.tag,
							onchange="Mailing.toggleTags('#arguments.fundID#');"
						)#
					</cfloop>
					
					<cfloop query="local.mailing">
						#$.render.triRadio(
							name="mailing_#local.mailing.id#",
							value="",
							label=local.mailing.name,
							onchange="Mailing.toggleTags('#arguments.fundID#');",
							class="mailingFilter"
						)#
					</cfloop>
				</td>
			</tr>
			<tr class="sort" style="display:none;">
				<td style="width:430px;text-align:right;">
					#$.render.radio(
						name="sort_#arguments.fundID#",
						value="created",
						labels=['name','amount','tagged','created'],
						values=['name','amount','tags','created'],
						onchange="Mailing.changeSort('#arguments.fundID#');"
					)#
					&nbsp;
					#$.render.radio(
						name="order_#arguments.fundID#",
						value="asc",
						labels=['asc','desc'],
						values=['asc','desc'],
						onchange="Mailing.changeSort('#arguments.fundID#');"
					)#
				</td>
			</tr>
			#renderMailingListRow(
				fundID=arguments.fundID,
				blankRow=true,
				currentRow=0,email="",name="",amount=""
			)#
		</cfsavecontent>
	
		<cfreturn $.render.clean(local.result) />
		
	</cffunction>
	
	<!--- --->

</cfcomponent>